package com.byq.mm.smartlib.tools;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;
import com.byq.mm.smartlib.R;
import com.byq.mm.abstractx.cluster.server.DeviceServer;
import com.byq.mm.abstractx.device.Cluster;


public class ClusterServerAdapter extends BaseAdapter {
	private LayoutInflater inflator;
	Context context;
	Cluster[] clusters;
	public ClusterServerAdapter(Context ctx, DeviceServer server) {
		super();
		
		this.context = ctx;
		inflator = LayoutInflater.from(ctx);
		this.server = server;
		clusters =  server.getDevice().getSupportedClusters().toArray(new Cluster[0]);
		

	}
	DeviceServer server;
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return clusters.length;
		
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return clusters[position];
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	@Override
	public View getView(int position, View cv, final ViewGroup parent) {
		if(cv == null){
			final Cluster c = clusters[position];
			cv = inflator.inflate(R.layout.list_item_icon_text_permit, null);
			cv.setTag(c);
			TextView name = (TextView)cv.findViewById(R.id.text);
			name.setText(c.getAlias());
			ImageView icon = (ImageView)cv.findViewById(R.id.icon);

			
			
			Drawable da = IconManager.getIconDrawable(context, c.getId());
			icon.setImageDrawable(da);
			ToggleButton permit = (ToggleButton)cv.findViewById(R.id.permit);
			permit.setOnCheckedChangeListener(new ToggleButton.OnCheckedChangeListener(){

				@Override
				public void onCheckedChanged(CompoundButton buttonView,
						boolean isChecked) {
					
					
				}
				
			});
		}
		return cv;
	}
	

	
}